/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package lu.med.praxiswahl.wahlumed.dao.beans;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import lu.med.praxiswahl.wahlumed.dao.beans.daointerface.BufferDAOInt;
import lu.med.praxiswahl.wahlumed.model.beans.BufferTBL;

/**
*
* @author Patrick kendzo
* Email: pkendzo@msn.com
*/
@Stateless
public class BufferDAO implements BufferDAOInt{

	@PersistenceContext(unitName = "gynaekomedic-ejbPU")
	private EntityManager	em	= null;
	
	@Override
	public void delete(String todo)
	{
		BufferTBL buff = em.find(BufferTBL.class, todo);
		if(buff != null)
		{
			em.remove(buff);
			em.flush();
		}
		
		
	}

	@Override
	public void persist(BufferTBL todo)
	{
		em.persist(todo);
		em.flush();
		
	}

	@Override
	public String getCustomerInLab()
	{
		try
		{
			BufferTBL query = (BufferTBL) em.createQuery(
			"select b from BufferTBL b where b.typ='LABOR'").getSingleResult();
			return query.getMatricule();
		}
		catch (Exception e)
		{
			return null;
		}
	}

	@Override
	public void update(BufferTBL todo)
	{
		em.merge(todo);
		em.flush();
		
	}

	@Override
	public String getCustomerInConsultingRoom()
	{
		try
		{
			BufferTBL query = (BufferTBL) em.createQuery(
			"select b from BufferTBL b where b.typ='CONSULTINGROOM'").getSingleResult();
			return query.getMatricule();
		}
		catch (Exception e)
		{
			return null;
		}
	}
	
	@Override
	public BufferTBL findTypByID(String typ) {
		
		return em.find(BufferTBL.class, typ);
	}
}
